<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h4 class="modal-title">编辑收货人信息</h4>
</div>
<div class="modal-body">
    <span style="font-size: small;color: grey;padding-left: 5px">发货单号</span>
    <span style="padding-left: 5px">{{ $delivery->delivery_no }}</span>
    <span style="font-size: small;color: grey;padding-left: 5%">订单单号</span>
    <span style="padding-left: 5px">{{ $delivery->order_no }}</span>
    <form id="edit-form" action="/xqc/customer-delivery/delivery-cn-ajax" method="post" onsubmit="return checkEditForm();">
        <style>
            .table > tbody > tr > td > label.asterisk:after {
                content: " *";
                color: red;
            }
            .form-copy {
                width: 200px;
                margin-right: 5px;
                border-radius: 0;
                box-shadow: none;
                padding: 4px 12px 7px 12px;
                font-size: 14px;
                line-height: 1.42857143;
                color: #555;
                border: 1px solid #ccc;
                transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
            }
        </style>
        <div class="box box-solid no-margin box-show">
            <div class="box-body">
                <h6 style="font-weight: bolder">收货人信息</h6>
                <div class="box-body table-responsive no-padding">
                    <table class="table">
                        <tbody>
                        <tr>
                            <td style="text-align: right;width: 100px;">
                                <label class="asterisk" style="padding-top: 8px;">国家</label>
                            </td>
                            <td style="text-align: left;width: 200px;">
                                <input type="text" class="form-copy" name="param[country]" value="{{ $delivery->receiver->country ?? '' }}" placeholder="国家" required>
                            </td>
                            <td style="text-align: right;width: 100px;">
                                <label class="asterisk" style="padding-top: 8px;" >收货人</label>
                            </td>
                            <td style="text-align: left;">
                                <input type="text" class="form-copy" name="param[receiver]" value="{{ $delivery->receiver->receiver ?? '' }}" placeholder="收货人" required>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    <table class="table">
                        <tbody>
                        <tr>
                            <td style="text-align: right;width: 100px;">
                                <label class="asterisk" style="padding-top: 8px;">收货地址</label>
                            </td>
                            <td colspan="3" style="text-align: left;">
                                <input type="text" class="form-copy" style="width: 520px;" name="param[address]" value="{{ $delivery->receiver->address ?? '' }}" placeholder="收货地址" required>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    <table class="table">
                        <tbody>
                        <tr>
                            <td style="text-align: right;width: 100px;">
                                <label style="padding-top: 8px;">州</label>
                            </td>
                            <td style="text-align: left;width: 200px;">
                                <input type="text" class="form-copy" name="param[state]" value="{{ $delivery->receiver->state ?? '' }}" placeholder="州">
                            </td>
                            <td style="text-align: right;width: 100px;">
                                <label style="padding-top: 8px;" >城市</label>
                            </td>
                            <td style="text-align: left;">
                                <input type="text" class="form-copy" name="param[city]" value="{{ $delivery->receiver->city ?? '' }}" placeholder="城市">
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    <table class="table">
                        <tbody>
                        <tr>
                            <td style="text-align: right;width: 100px;">
                                <label style="padding-top: 8px;">邮编</label>
                            </td>
                            <td style="text-align: left;width: 200px;">
                                <input type="text" class="form-copy" name="param[postcode]" value="{{ $delivery->receiver->postcode ?? '' }}" placeholder="邮编">
                            </td>
                            <td style="text-align: right;width: 100px;">
                                <label style="padding-top: 8px;" >电话</label>
                            </td>
                            <td style="text-align: left;">
                                <input type="text" class="form-copy" name="param[phone]" value="{{ $delivery->receiver->phone ?? '' }}" placeholder="电话">
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    <table class="table">
                        <tbody>
                        <tr>
                            <td style="text-align: right;width: 100px;">
                                <label style="padding-top: 8px;">税号</label>
                            </td>
                            <td colspan="3" style="text-align: left;">
                                <input type="text" class="form-copy" style="width: 520px;" name="param[cpf]" value="{{ $delivery->receiver->cpf ?? '' }}" placeholder="税号" required>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="box box-solid no-margin box-show">
            <div class="box-body">
                <h6 style="font-weight: bolder">商品信息</h6>
                <div class="box-body table-responsive no-padding" style="max-height: 600px;">
                    <table class="table table-hover">
                        <thead>
                        <tr>
                            <th>SKU</th>
                            <th width="25%">产品名称</th>
                            <th>申请发货数量</th>
                            <th>备货数量</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($delivery->detail as $item)
                            <tr>
                                <td>{{ $item->sku->psku_code ?? '' }}</td>
                                <td>{{ $item->sku->psku_cn ?? '' }}</td>
                                <td>{{ $item->apply_num }}</td>
                                <td><span class="label label-{{ $item->apply_num > $item->ship_num ? 'danger' : 'info'}}">{{ $item->ship_num }}</span></td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="modal-footer">
            {{ csrf_field() }}
            <input type="hidden" name="action" value="doListEdit">
            <input type="hidden" name="param[id]" value="{{ $id }}">
            <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            <button type="submit" class="btn btn-primary">确认</button>
        </div>
    </form>
</div>
<script language="JavaScript" type="text/javascript">
    function checkEditForm(){
        var country = $('input[name="param[country]"]').val();
        if(country.trim() == ''){
            swal('收货国家不能为空', '', 'error');
            return false;
        }
        var receiver = $('input[name="param[receiver]"]').val();
        if(receiver.trim() == ''){
            swal('收货人不能为空', '', 'error');
            return false;
        }
        var address = $('input[name="param[address]"]').val();
        if(address.trim() == ''){
            swal('收货地址不能为空', '', 'error');
            return false;
        }
    }
    $(function () {
        $("#edit-form").ajaxForm(function (data) {
            $("#listCommonModal").modal('hide');
            $(".modal-backdrop").remove();
            $('body').removeClass('modal-open');
            if (typeof data === 'object') {
                if (data.status) {
                    toastr.success(data.message);
                } else {
                    swal(data.message, '', 'error');
                }
            }
        });
    });
</script>
